console.log("主任务");

// 以下两种写法相同

// new Promise<void>((resolve) => {
//   resolve();
// }).then(() => {});

// Promise.resolve().then(() => {})

Promise.resolve().then(() => {
  console.log("微任务1");
});

setTimeout(() => {
  console.log("宏任务1");

  Promise.resolve()
    .then(() => {
      console.log("微任务3");
    })
    .then(() => {
      console.log("微任务5");
    });

  setTimeout(() => {
    console.log("宏任务2");
  }, 0);

  Promise.resolve().then(() => {
    console.log("微任务4");
  });

  setTimeout(() => {
    console.log("宏任务3");
  }, 0);
}, 0);

Promise.resolve().then(() => {
  console.log("微任务2");
});

console.log("主任务1");
